import requests
import json
import configparser
# 创建ConfigParser对象
config = configparser.ConfigParser()
# 读取配置文件
config.read('config.ini')
# 获取配置项的值
API_KEY = config.get('baidu', 'API_KEY')
SECRET_KEY = config.get('baidu', 'SECRET_KEY')
model_name_list = config.get('baidu', 'model_name_list')
model_name_list = model_name_list.split(',')
import requests
import json


def baidu_api(messages,model_name="ernie-3.5-128k"):
    url = "https://qianfan.baidubce.com/v2/chat/completions"
    # url = "http://nlp.db.org:8108/v1/chat/completions"
    # url = "http://10.27.6.1:11434/api/chat"
    payload = json.dumps({
        "model": model_name,
        # "model": "deepseek-r1:32b",
        "messages": messages,
        "stream": False,
        "temperature":0.3
    }, ensure_ascii=False)
    headers = {
        'Content-Type': 'application/json',
        'appid': 'app-fwMCbR1J',
        'Authorization': 'Bearer bce-v3/ALTAK-FA7minoIr4FaKRLIuw9B3/f12ebcc69275cfe5a3c03a699e26c39eb0ce3071'
    }
    # headers = {
    #     "Accept": "*/*",
    #     "Accept-Encoding": "gzip, deflate, br",
    #     "User-Agent": "PostmanRuntime-ApipostRuntime/1.1.0",
    #     "Connection": "keep-alive",
    #     "Content-Type": "application/json"
    # }

    response = requests.request("POST", url, headers=headers, data=payload.encode("utf-8"))
    print(response.text)
    id,model_name,choice,message,content = paraString(response.text)
    return content

def paraString(text):
    json_str = json.loads(text)
    id = json_str.get('id')
    model_name = json_str.get('model')
    choice = json_str['choices'][0]
    message = choice['message']
    content = message['content']
    return id, model_name, choice,message, content

if __name__ == '__main__':
    prompt = "你是谁，你能做什么？"
    from conetnt_is_negative import prompt_text
    title = """
    #沿途随拍 预计22:10起飞🛫，因为下雨🌧️还在等。山航不是很猛的吗？👀🐲龙王停停雨，我想回家🛶#此时此刻 #去想去的地方 Home


    """
    content = """
    #沿途随拍 预计22:10起飞🛫，因为下雨🌧️还在等。山航不是很猛的吗？👀🐲龙王停停雨，我想回家🛶#此时此刻 #去想去的地方 Home<video src='http://v3-web.toutiaovod.com/afa5a8ffbec12c20ccd2122220856c05/6699f241/video/tos/cn/tos-cn-ve-15/oMiKvQBfmqAjzMlZBpFEgnD1AmA9XHOEIhfwDS/?a=24&ch=94349491494&cr=0&dr=0&lr=no_logo&net=5&cd=0%7C0%7C0%7C0&br=1018&bt=1018&cs=0&ds=3&ft=WbaUMqBrffPdOP~-hv3NvAq-antLjrKucMd.Rkah.aD_ejVhWL6&mime_type=video_mp4&qs=0&rc=ZDk1Ojs2NjQ3Nmg3NzVmaEBpajdmNnk5cnlsdDMzNDlpM0A1MmM1NTFjXmAxX2AwLjYyYSMxb3MuMmRraWBgLS1kMDBzcw%3D%3D&btag=80000e00008000&dy_q=1721361448&feature_id=f0150a16a324336cda5d6dd0b69ed299&l=20240719115728B785D57ADD7BE2C7FAE7'></video>



    """
    ocr = ""
    prompt = prompt_text.format(monitoring_subject="航空机构",title=title, content=content, ocr=ocr)
    model_name = model_name_list[0]
    result = baidu_api(model_name = model_name,messages = [
        {
        "role":"user",
        "content":prompt
        }
    ])
    print(f"{model_name}:{result}")